package com.ftg.exam.manage.controller;

import com.ftg.exam.manage.pojo.OneChoice;
import com.ftg.exam.manage.service.OneChoiceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zwl
 * 单选题controller
 * Created on 2019/8/13 11:35
 */
@RestController
@CrossOrigin
@RequestMapping("/one")
public class OneChoiceController {
    @Autowired
    OneChoiceService oneChoiceService;
    @PostMapping("/show")
    public Map<String, Object> showall(@RequestBody OneChoice pageH) {
        System.out.println(pageH+"88888");
        //开始分页Admin>集合
        PageHelper.startPage(pageH.getPage(),pageH.getLimit());
        //用List< 去存service层调用的方法
        List<OneChoice> list = oneChoiceService.showall(pageH);
        //包装查询后的结果
        PageInfo<OneChoice> page = new PageInfo<>(list);
        //实例化map结果集
        Map<String,Object> map = new HashMap<>();
        //将list中的数据放入map中
        map.put("data",list);
        //code码 为0
        map.put("code","0");
        //成功信息为success
        map.put("msg","success");
        //将总数据条数放入map中
        map.put("count",page.getTotal());
        //返回map
        return map;
    }
    @PostMapping("/shows")
    public Map<String,Object> showDifficulty(){
        List<OneChoice> list = oneChoiceService.showDifficulty();
        Map<String,Object> map=new HashMap<>();
        map.put("code","0");
        map.put("msg","");
        map.put("d1",list);
        return map;
    }

    @PostMapping("/update")
    public int update(OneChoice oneChoice){
        return oneChoiceService.update(oneChoice);
    }

    @DeleteMapping("/delete/{id}")
    public int delete(@PathVariable("id") String id){
        return oneChoiceService.delete(id);
    }

    @PostMapping("/save")
    public int save(@RequestBody OneChoice oneChoice){
        return oneChoiceService.save(oneChoice);
    }
    @PostMapping("/showone")
    public Map<String, Object> showone(@RequestBody OneChoice pageH) {
        if(pageH.getWrite() == null){
            pageH.setWrite("");
        }
        //开始分页Admin>集合
        PageHelper.startPage(pageH.getPage(),pageH.getLimit());
        //用List< 去存service层调用的方法
        List<OneChoice> list = oneChoiceService.showone(pageH);
        //包装查询后的结果
        PageInfo<OneChoice> page = new PageInfo<>(list);
        //实例化map结果集
        Map<String,Object> map = new HashMap<>();
        //将list中的数据放入map中
        map.put("data",list);
        //code码 为0
        map.put("code","0");
        //成功信息为success
        map.put("msg","success");
        //将总数据条数放入map中
        map.put("count",page.getTotal());
        //返回map
        return map;
    }


}
